<template>
  <div class="musicTop">
    <div class="musicContentTop">
      <div class="playAllMusic" @click="playAll">
        <svg class="icon" aria-hidden="true">
          <use xlink:href="#icon-bofang"></use>
        </svg>
        <span
          >播放全部<i>(共{{ songs.length }}首)</i></span
        >
      </div>
      <div class="collectionMusic">
        <svg class="icon" aria-hidden="true">
          <use xlink:href="#icon-jiahao1"></use>
        </svg>
        <span>收藏({{ sub(subscribedCount) }})</span>
      </div>
    </div>
    <div class="musicContentFooter">
      <ul>
        <li v-for="(song, index) in songs" :key="song.id">
          <i class="index">{{ index + 1 }}</i>
          <div class="musicNameAndAuthor" @click="playXMusic(index)">
            <span class="musicName">{{ song.name }}</span>
            <div class="allName">
              <i
                style="
                  font-style: normal;
                  opacity: 0.5;
                  margin-top: 0.15rem;
                  font-size: 0.25rem;
                  margin-right: 0.2rem;
                "
                v-for="ar in song.ar"
                :key="ar.id"
                >{{ ar.name }}</i
              >
            </div>
          </div>
          <div class="twoIcon">
            <svg class="icon" aria-hidden="true" v-if="song.mv">
              <use xlink:href="#icon-24gl-playSquare"></use>
            </svg>
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-caidan"></use>
            </svg>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { useStore } from "vuex";

export default {
  props: ["songs", "subscribedCount"],
  setup(props) {
    let { commit, dispatch } = useStore();
    //方法 计算收藏
    function sub(num) {
      return (num / 10000).toFixed(1) + "万";
    }
    //方法 更换歌曲
    function playXMusic(index) {
      commit("UPDATEPLAYLIST", { list: props.songs, index });
      dispatch("getMusicLyric", props.songs[index].id);
    }

    //方法 播放全部音乐
    function playAll() {
      commit("UPDATEPLAYLIST", { list: props.songs, index: 0 });
    }

    return { sub, playXMusic, playAll };
  },
};
</script>

<style lang="less" scoped>
.musicTop {
  margin-top: 0.2rem;
  width: 100%;
  height: 20rem;
  background-color: #fff;
  border-top-left-radius: 0.4rem;
  border-top-right-radius: 0.4rem;
  padding-top: 0.2rem;
  .musicContentTop {
    display: flex;
    justify-content: space-between;
    .playAllMusic {
      margin-left: 0.2rem;
      display: flex;
      align-items: center;
      .icon {
        fill: rgba(117, 112, 112, 0.729);
      }
      span {
        font-weight: 900;
        margin-left: 0.2rem;
        i {
          font-style: normal;
          font-weight: normal;
          font-size: 0.25rem;
          opacity: 0.5;
        }
      }
    }
    .collectionMusic {
      display: flex;
      align-items: center;
      width: 2.1rem;
      height: 0.7rem;
      background-color: red;
      border-radius: 0.4rem;
      margin-right: 0.2rem;
      .icon {
        fill: #fff;
        width: 0.4rem;
      }
      span {
        margin: 0 0.1rem 0 0.1rem;
        color: #fff;
        font-size: 0.25rem;
      }
    }
  }
  .musicContentFooter {
    margin-top: 0.3rem;
    ul li {
      display: flex;
      justify-content: space-between;
      line-height: 100%;
      padding-left: 0.2rem;
      margin-top: 0.25rem;
      .index {
        width: 0.4rem;
        height: 0.5rem;
        text-align: center;
        line-height: 0.5rem;
        font-style: normal;
      }
      .musicNameAndAuthor {
        flex: 2;
        margin-left: 0.1rem;
        display: flex;
        flex-direction: column;
        .musicName {
          width: 5.5rem;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }
      .allName {
        width: 2.5rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      .twoIcon {
        flex: 0.5;
        .icon:first-child {
          float: left;
        }
        .icon:last-child {
          float: right;
          margin-right: 0.2rem;
        }
      }
    }
  }
}
</style>